const { ethers } = require("hardhat");

async function main() {
    console.log("🔍 检查合约编译状态...\n");

    // 检查合约是否在 artifacts 中
    const contractNames = ["LogicContractV1", "LogicContractV2", "ProxyContract"];

    for (const name of contractNames) {
        try {
            const factory = await ethers.getContractFactory(name);
            console.log(`✅ ${name} 合约工厂加载成功`);

            // 尝试部署一个临时实例来测试
            console.log(`  测试部署 ${name}...`);
            const tempContract = await factory.deploy();
            await tempContract.waitForDeployment();
            const address = await tempContract.getAddress();
            const code = await ethers.provider.getCode(address);
            console.log(`  ${name} 测试部署成功，代码长度: ${code.length}`);

            // 清理：销毁临时合约
            // 在 Hardhat 网络中不需要手动清理
        } catch (error) {
            console.log(`❌ ${name} 出现问题:`, error.message);
        }
    }
}

main()
    .then(() => process.exit(0))
    .catch((error) => {
        console.error("检查失败:", error);
        process.exit(1);
    });
